<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/18
 * Time: 17:32
 */

namespace app\admin\controller;
use app\admin\model\OrderModel;
class Order extends Base{
    //需求订单
    public function index(){
        if(request()->isAjax()){
            $param = input('param.');
            $limit = $param['pageSize'];
            $offset = ($param['pageNumber'] - 1) * $limit;
            $where = [];
            if (paramValid($param,'mobile')) $where['mobile'] = ['like', '%' . $param['mobile'] . '%'];
            if (paramValid($param,'order_sn')) $where['order_sn'] = ['like', '%' . $param['order_sn'] . '%'];
            if(isset($param['type']) && $param['type']!=0){
                switch($param['type']){
                    case 1:
                        $where['pay_status']=0;
                        break;
                    case 2:
                        $where['pay_status']=1;
                        break;
                }
            }
            $model = new OrderModel();
            $selectResult = $model->getOrder($where, $offset, $limit);
            // 拼装参数
            foreach($selectResult as $key=>$vo){
                $selectResult[$key]['addtime']=date('Y-m-d H:i:s',$vo['addtime']);
                //$selectResult[$key]['type']=order_type($vo['type']);
                $selectResult[$key]['pay_status']=pay_status($vo['pay_status']);
                $selectResult[$key]['operate'] = '';
            }
            $return['total'] = $model->getAll($where);  //总数据
            $return['rows'] = $selectResult;

            return json($return);
        }
        $param=input('param.');
        $data['sch']=json_encode(array(
            array('id'=>'mobile','name'=>'用户手机号'),
            array('id'=>'order_sn','name'=>'订单编号')
        ));
        $this->assign([
            'data' => $data
        ]);
        return $this->fetch();
    }
}